package io;

import java.io.*;
import java.nio.charset.StandardCharsets;

public class Work1 {
    public static void main(String[] args) throws IOException, ClassNotFoundException {
        /*
        缓冲流实现文件的复制--------CopyDemo3Buffered
        对象流读写对象---------------Student+OOSDemo+OISDemo
        转换流读写字符---------------OSWDemo+ISRDemo

         */
        //缓冲流实现文件的复制
        /*
        FileInputStream fis = new FileInputStream("xjp.jpg");
        BufferedInputStream bis = new BufferedInputStream(fis);
        FileOutputStream fos = new FileOutputStream("xjp_cp4.jpg");
        BufferedOutputStream bos = new BufferedOutputStream(fos);
        long start = System.currentTimeMillis();
        int d;
        while ((d = bis.read())!=-1){
            bos.write(d);
        }
        long end = System.currentTimeMillis();
        System.out.println("复制完毕!耗时:"+(end-start)+"ms");
        bis.close();
        bos.close();
         */
        /*
        FileInputStream fis = new FileInputStream("xjp.jpg");
        BufferedInputStream bis = new BufferedInputStream(fis);
        FileOutputStream fos = new FileOutputStream("xjp_cp4.jpg");
        BufferedOutputStream bos = new BufferedOutputStream(fos);
        long start = System.currentTimeMillis();
        int d;
        while ((d= bis.read())!=-1){
            bos.write(d);
        }
        long end = System.currentTimeMillis();
        System.out.println("复制完毕!耗时:"+(end-start)+"ms");
        bis.close();
        bos.close();
         */
        //对象流读写对象
        /*
        String name = "张三";
        int age = 18;
        String gender = "男";
        String[] otherInfo = {"是一名学生","黑龙江佳木斯的","喜欢打篮球","喜欢王老师"};
        Student1 zs = new Student1(name,age,gender,otherInfo);
        System.out.println(zs);
        FileOutputStream fos = new FileOutputStream("student1.obj");
        ObjectOutputStream oos = new ObjectOutputStream(fos);
        oos.writeObject(zs);
        oos.close();
         */
        /*
        FileInputStream fis = new FileInputStream("student1.obj");
        ObjectInputStream ois = new ObjectInputStream(fis);
        Object obj = ois.readObject();
        Student1 zs = (Student1) obj;
        System.out.println(zs);
        ois.close();
        */
        /*
        String name = "张三";
        int age = 18;
        String gender = "男";
        String[] otherInfo = {"是一名学生","黑龙江佳木斯的","喜欢打篮球","喜欢王老师"};
        Student1 zs = new Student1(name,age,gender,otherInfo);
        System.out.println(zs);
        FileOutputStream fos = new FileOutputStream("student1.obj");
        ObjectOutputStream oos = new ObjectOutputStream(fos);
        oos.writeObject(zs);
        oos.close();
         */
        /*
        FileInputStream fis = new FileInputStream("student1.obj");
        ObjectInputStream ois = new ObjectInputStream(fis);
        Object obj = ois.readObject();
        Student1 zs = (Student1) obj;
        System.out.println(zs);
        ois.close();
         */
        //转换流读写字符
        /*
        FileOutputStream fos = new FileOutputStream("osw1.txt");
        OutputStreamWriter osw = new OutputStreamWriter(fos, StandardCharsets.UTF_8);
        osw.write("和我在成都的街头走一走，哦哦哦哦...");
        osw.write("直到所有的灯都熄灭了也不停留");
        System.out.println("写出完毕!");
        osw.close();

        FileInputStream fis = new FileInputStream("osw1.txt");
        InputStreamReader isr = new InputStreamReader(fis,StandardCharsets.UTF_8);
        int d;
        while ((d = isr.read())!=-1){
            System.out.println((char) d);
        }
        isr.close();
         */
        /*
        FileOutputStream fos = new FileOutputStream("osw1.txt");
        OutputStreamWriter osw = new OutputStreamWriter(fos,StandardCharsets.UTF_8);
        osw.write("和我在成都的街头走一走，哦哦哦哦...");
        osw.write("直到所有的灯都熄灭了也不停留");
        osw.close();

        FileInputStream fis = new FileInputStream("osw1.txt");
        InputStreamReader isr = new InputStreamReader(fis,StandardCharsets.UTF_8);
        int d;
        while ((d = isr.read())!=-1){
            System.out.println((char) d);
        }
        isr.close();
         */
    }
}
